package mybatis.mapper;

import mybatis.pojo.Worker;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

public interface WorkerMapper {
    //修改sql语句修改结果集将worker_id字段改为workerId
    @Select("select * from tb_worker where id = #{id}")
//    @Results({
//            @Result(column = "id", property = "id"),
//            @Result(column = "name", property = "name"),
//            @Result(column = "age", property = "age"),
//            @Result(column = "sex", property = "sex"),
//            @Result(column = "worker_id", property = "worker_id")
//    })
    Worker selectWorker(int id);

    @Insert("insert into tb_worker(name,age,sex,worker_id)"
            +"values(#{name},#{age},#{sex},#{worker_id})")
    int insertWorker(Worker worker);

    @Update("update tb_worker set name = #{name},age = #{age} "
            +"where id = #{id}")
    int updateWorker(Worker worker);

    @Delete("delete from tb_worker where id = #{id}")
    int deleteWorker(int id);
    @Delete("<script>" +
            "DELETE FROM tb_worker WHERE id IN " +
            "<foreach collection='workers' item='worker' open='(' separator=',' close=')'>" +
            "#{worker.id}" +
            "</foreach>" +
            "</script>")
    void deleteWorkers(@Param("workers") List<Worker> workers);


}

